package cloud.estate.commons.handler;

import cloud.estate.commons.handler.exception.*;
import cloud.estate.commons.util.JsonResult;
import cloud.estate.commons.util.ResultTool;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器，用于统一处理系统中抛出的异常
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(AddOneException.class)
    public JsonResult addOneExceptionHandler(Throwable e) {
        return ResultTool.fail(601, e.getMessage());
    }
    @ExceptionHandler(FindOneException.class)
    public JsonResult findOneExceptionHandler(Throwable e) {
        return ResultTool.fail(602, e.getMessage());
    }
    @ExceptionHandler(FindAllException.class)
    public JsonResult findAllExceptionHandler(Throwable e) {
        return ResultTool.fail(603, e.getMessage());
    }
    @ExceptionHandler(DealOneByIdException.class)
    public JsonResult dealOneByIdExceptionHandler(Throwable e) {
        return ResultTool.fail(604, e.getMessage());
    }
    @ExceptionHandler(UpdateOneException.class)
    public JsonResult updateOneExceptionHandler(Throwable e) {
        return ResultTool.fail(605, e.getMessage());
    }
}


